package org.abacus.hibernate;

import org.abacus.hibernate.model.HibernateModel;
import org.junit.Test;

public class HibernateSessionFilterTest {
	protected static final String hibernate_cfg_core_xml = "/hibernate/core/hibernate.cfg.xml";
	static {
		HibernateSessionFactoryProvider.getInstance().addTag(hibernate_cfg_core_xml);
		HibernateSessionProvider.addTag(hibernate_cfg_core_xml);
	}
	SessionFilter filter = new HibernateSessionFilter();
	TransactionStrategy txs = HibernateTransactionStrategy.getInstance();

	@Test
	public void testStart() {
		try {
			filter.open();
			txs.begin();
			HibernateModel m = new HibernateModel();
			m.setCode("reason");
			HibernateSessionProvider.getCurrentSession(hibernate_cfg_core_xml).save(m);
			m = new HibernateModel();
			m.setCode("reason");
			HibernateSessionProvider.getCurrentSession(hibernate_cfg_core_xml).save(m);
			m = new HibernateModel();
			m.setCode("reason");
			HibernateSessionProvider.getCurrentSession(hibernate_cfg_core_xml).save(m);
			txs.commit();
			filter.close();
		} catch (Exception e) {
			txs.rollback();
			e.printStackTrace();
		}
	}

}
